var year = 2019 ; //现在当前的年份
var mounth = 5; //现在当前的月份
document.querySelector("#nian").innerHTML = year;
document.querySelector("#yue").innerHTML = mounth;
var days = 0; //总天数

//判断这年是不是闰年
function runNian(y){
    if(y % 400 === 0 || (y % 4 === 0 && y % 100 !==0)){
        return true;
    }else {
        return false;
    }
}

//从1980年到2019年一共有多少天

for (var i = 1980 ; i < year ; i++){
    if (runNian(i)){
        days += 366;
    }else {
        days += 365;
    }
}


//获取每年的月份有多少天 31 28 31 30 31 30 31 31 30 31 30 31

for(var k = 1 ; k < mounth ; k++){
    switch (k){
        case 1:
            days += 31;
            break;
        case 2:
            if(runNian(year)){
                days += 29;
            }else {
                days += 28;
            }
            break;
        case 3:
            days += 31;
            break;
        case 4:
            days += 30;
            break;
        case 5:
            days += 31;
            break;
        case 6:
            days += 30;
            break;
        case 7:
            days += 31;
            break;
        case 8:
            days += 31;
            break;
        case 9:
            days += 30;
            break;
        case 10:
            days += 31;
            break;
        case 11:
            days += 30;
            break;
        case 12:
            days += 31;
            break;
    }
}

//本月一共有多少天

var day = 0;
switch (mounth){
    case 1:
        day += 31;
        break;
    case 2:
        if(runNian(year)){
            day += 29;
        }else {
            day += 28;
        }
        break;
    case 3:
        day += 31;
        break;
    case 4:
        day += 30;
        break;
    case 5:
        day += 31;
        break;
    case 6:
        day += 30;
        break;
    case 7:
        day += 31;
        break;
    case 8:
        day += 31;
        break;
    case 9:
        day += 30;
        break;
    case 10:
        day += 31;
        break;
    case 11:
        day += 30;
        break;
    case 12:
        day += 31;
        break;
}
console.log(day);


//上一个月有多少天
var prevDay = 0;
if (mounth == 1){
    prevDay += 31;
}else {
    switch (mounth - 1) {
        case 1:
            prevDay += 31;
            break;
        case 2:
            if (runNian(year)) {
                prevDay += 29;
            } else {
                prevDay += 28;
            }
            break;
        case 3:
            prevDay += 31;
            break;
        case 4:
            prevDay += 30;
            break;
        case 5:
            prevDay += 31;
            break;
        case 6:
            prevDay += 30;
            break;
        case 7:
            prevDay += 31;
            break;
        case 8:
            prevDay += 31;
            break;
        case 9:
            prevDay += 30;
            break;
        case 10:
            prevDay += 31;
            break;
        case 11:
            prevDay += 30;
            break;
        case 12:
            prevDay += 31;
            break;
    }
}
console.log(prevDay);


//1980 01 01 是星期二，让它从周日开始算

days += 2;
console.log(days);

//求出本月的一号是星期几

var start = days % 7;

if(start == 0){
    start += 7;
}
//每个月显示多少天

var num = 42;

var nextDays = num - start - day;
console.log(nextDays);
//当前日期
var thisdate =new Date().getDate();

var date1 = document.querySelector("#day1");


/*if(prevDay -start + 1 > prevDay){
    for (var j = prevDay - 7 + 1 ; j <= prevDay ; j++){
        date1.innerHTML += "<span class='h'>" + j + "</span>";
    }
}else {
    for (var l = prevDay - start + 1; l <= prevDay ; l++){
        date1.innerHTML += "<span class='h'>" + l + "</span>";
    }
}
console.log(j);*/

for (var l = prevDay - start + 1; l <= prevDay ; l++){
        date1.innerHTML += "<span class='h'>" + l + "</span>";
    }



for (var t = 1;t <= day ; t++){
    if(t == thisdate){
        date1.innerHTML += "<span class='today'>" + t + "</span>";
    }else {
        date1.innerHTML += "<span>" + t + "</span>";
    }
}



/*if(prevDay -start + 1 > prevDay){
    for (var n = 1; n <= num - 7 - day ; n++){
        date1.innerHTML += "<span class='h'>" + n + "</span>";
    }
}else {
    for (var w = 1; w <= nextDays ; w++){
        date1.innerHTML += "<span class='h'>" + w + "</span>";
    }
}*/
for (var w = 1; w <= nextDays ; w++){
    date1.innerHTML += "<span class='h'>" + w + "</span>";
}
